import java.util.Random;

public class Array {
    public static void main(String[] args) {


        //求最值
        int[] arr={33,5,22,44,55};
        int max=arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(arr[i]>max){
                max=arr[i];
            }
        }
        System.out.println(max);//55

        System.out.println("---------------------------");


        //求和
        //生成10个1-100的随机数
        int[] arr1=new int[10];
        Random r=new Random();
        for (int i = 0; i < arr1.length; i++) {
            int num=r.nextInt(100)+1;
            arr1[i]=num;
        }
        //1、求和
        int sum=0;
        for (int i = 0; i < arr1.length; i++) {
            sum=sum+arr1[i];
        }
        System.out.println("和为："+sum);
        //2、求平均数
        int avg=sum/ arr1.length;
        System.out.println("平均数为："+avg);
        //3、统计有多少个数据比平均值小
        int count=0;
        for (int i = 0; i < arr1.length; i++) {
            if(arr1[i]<avg){
                count++;
            }
        }
        System.out.println("有"+count+"个数据比平均数小");
        //遍历数组验证
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i]+" ");
        }

        System.out.println("---------------------------");


        //4、交换数据
        int[] arr2={1,2,3,4,5};
        for (int i = 0,j=arr.length-1; i < j; i++,j--) {
            int t=arr2[i];
            arr2[i]=arr[j];
            arr[j]=t;
        }
        for (int i = 0; i < arr2.length; i++) {
            System.out.print(arr2[i]+" ");
        }

        System.out.println("---------------------------");


        //5、打乱数据
        int[] arr3={1,2,3,4,5};
        Random r1=new Random();
        for (int i = 0; i < arr3.length; i++) {
            int randomIndex=r1.nextInt(arr3.length);
            int temp=arr3[i];
            arr3[i]=arr3[randomIndex];
            arr3[randomIndex]=temp;
        }
        for (int i = 0; i < arr3.length; i++) {
            System.out.print(arr3[i]+" ");
        }
    }
}
